<?php
namespace app\controllers\home;

use fate\http\Request;
use app\libs\LibUser;
use app\models\User;
use app\models\Fans;
use app\libs\Sys;

// 用户中心 使用 struid
class IndexController extends \fate\web\Controller {
    public function run() {
        $this->getView()->enableLayout = true;

        $req = Request::getInstance();
        $encodeUid = $req->getQueryString('uid');
        $uid = LibUser::decodeId($encodeUid);

        if(!is_numeric($uid)) {
            throw new \Exception('user not found');
            exit;
        }

        $user = new User();
        $userInfo = $user->getOne('gender,user_name,avatar,short_intro', $uid);

        if(null === $userInfo) {
            throw new \Exception('user not found');
            exit;
        }

        $fansModel = new Fans();
        $fans = $fansModel->fansNumber($uid);
        $follows = $fansModel->followsNumber($uid);

        $bannerBasePath = Sys::getBannerUploadPath($uid);
        $this->render('@themes/home/index', [
            'fans' => $fans,
            'follows' => $follows,
            'strUid' => $encodeUid,
            'userInfo' => $userInfo,
            'banner' => is_file( './' . $bannerBasePath . "/{$uid}.jpg" )
                ? ('/' . $bannerBasePath . "/{$uid}.jpg")
                : ''
        ]);
    }
}
